package com.example.mushroom.controller;

import com.example.mushroom.entity.SensorData;
import com.example.mushroom.service.SensorDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/sensor-data")
public class SensorDataController {

    @Autowired
    private SensorDataService sensorDataService;

    @PostMapping
    public int insertSensorData(@RequestBody SensorData sensorData) {
        return sensorDataService.insertSensorData(sensorData);
    }

    @GetMapping("/{id}")
    public SensorData selectSensorDataById(@PathVariable Integer id) {
        return sensorDataService.selectSensorDataById(id);
    }

    @GetMapping
    public List<SensorData> selectAllSensorData() {
        return sensorDataService.selectAllSensorData();
    }

    @GetMapping("/range")
    public List<SensorData> selectSensorDataByTimeRange(@RequestParam Date start, @RequestParam Date end) {
        return sensorDataService.selectSensorDataByTimeRange(start, end);
    }

    @PutMapping
    public int updateSensorData(@RequestBody SensorData sensorData) {
        return sensorDataService.updateSensorData(sensorData);
    }

    @DeleteMapping("/{id}")
    public int deleteSensorDataById(@PathVariable Integer id) {
        return sensorDataService.deleteSensorDataById(id);
    }

    @GetMapping("/page")
    public List<SensorData> selectSensorDataByPage(@RequestParam int offset, @RequestParam int limit) {
        return sensorDataService.selectSensorDataByPage(offset, limit);
    }
}